package com.lijie.ljblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lijie.ljblog.common.BlogConstants;
import com.lijie.ljblog.common.GameAbstractStrategy;
import com.lijie.ljblog.mapper.GameMapper;
import com.lijie.ljblog.mapper.GameScoreMapper;
import com.lijie.ljblog.model.Game;
import com.lijie.ljblog.model.GameScore;
import com.lijie.ljblog.model.dto.GameScoreDTO;
import com.lijie.ljblog.model.dto.GameScoreSaveDTO;
import com.lijie.ljblog.model.vo.GameGoBangScoreRankVO;
import com.lijie.ljblog.model.vo.GameScoreRankVO;
import com.lijie.ljblog.model.vo.GameScoreVO;
import com.lijie.ljblog.service.GameService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @Description
 * @Author lijie
 * @Date 2022/10/22 16:13
 **/
@Service
public class GameGoBangServiceImpl  extends GameAbstractStrategy implements GameService{
    @Resource
    GameMapper gameMapper;
    @Resource
    GameScoreMapper gameScoreMapper;

    public GameGoBangServiceImpl() {
        register(BlogConstants.GAME_TYPE_GOBANG);
    }

    /**
     * 根据人员和游戏名称获取得分
     *
     * @param gameScoreDTO
     * @return
     */
    @Override
    public GameScoreVO getGameScore(GameScoreDTO gameScoreDTO) {
        return null;
    }

    /**
     * 保存游戏数据
     *
     * @param gameScoreSaveDTO
     * @return
     */
    @Override
    public Boolean saveGameScore(GameScoreSaveDTO gameScoreSaveDTO) {
        GameScore gameScore = new GameScore();
        BeanUtils.copyProperties(gameScoreSaveDTO, gameScore);
        List<Game> games = gameMapper.selectList(new LambdaQueryWrapper<Game>().eq(Game::getGameName, gameScoreSaveDTO.getGameName()));
        gameScore.setGameId(games.get(0).getGameId());
        int insert = gameScoreMapper.insert(gameScore);
        return insert>0;
    }

    /**
     * 获得游戏得分排名
     *
     * @param gameScoreDTO
     * @return
     */
    @Override
    public List<GameGoBangScoreRankVO> getGameScoreRank(GameScoreDTO gameScoreDTO) {

        return gameScoreMapper.getGoBangScoreRank(gameScoreDTO);
    }
}
